    clear  

    cd '~/Dropbox/Data and Replication/Selective default risk/AAO_Selective Default Risk'

    %
    Bonds={'Argentina','Brazil','China','Portugal'}';

    % Bond prices and characteristics   
for b=1:4
                    % Dates
                    [ndata, text, alldata] = xlsread('_Data/Portfolio of risky bonds (1934)/Data_RiskyBonds_1934.xlsx',Bonds{b,1},'A1:I14');
                    t=datetime(xlsread('_Data/Portfolio of risky bonds (1934)/Data_RiskyBonds_1934.xlsx',Bonds{b,1},'A3:A14'),'convertfrom','excel','Locale','en_US');
                    t.Format= 'dd-MMM-yyyy';
                    
                    Maturity= datetime(strcat('1-Jan-',num2str(ndata(2,6))),'Locale','en_US');
                    Maturity.Format = 'dd-MMM-yyyy';
                    Price_Paris=cell2mat(alldata(3:end,4));
                    Price_London=cell2mat(alldata(3:end,5));
                    
                     
                    Prices=[Price_Paris,Price_London];
                    COUPON=cell2mat(alldata(3:end,7));
                    
  
                    Period=2;
                    Basis=0;
                    
                                      YTM=NaN(size(Prices));

                for r=1:2
                    for i=1:length(Prices)
                         YTM(i,r)= bndyield(Prices(i,r),COUPON(i,1),t(i,1),Maturity,Period,Basis);
                     end
                end
 
                
     HEADER={'Date';strcat('YTM_RB_',Bonds{b,1},'_Paris');strcat('YTM_RB_',Bonds{b,1},'London')};


     Panel=cell(length(YTM)+1,3);
     Panel(1,:)=HEADER';
     Panel(2:end,1)=cellstr(t);
     Panel(2:end,2:3)=num2cell(YTM);
 
 
     T = cell2table(Panel(2:end,:),'VariableNames',Panel(1,:));
       
     filename=strcat('_Data/Yield to maturity/YTM_riskybonds_','YTM_RB_',Bonds{b,1},'.csv');
    % Write the table to a CSV file
    writetable(T,filename)

 
end


  
  
 

  

     

 